import subprocess
import re
import os
import signal


class Gene_Trace():
    def __init__(self, com):
        self.com = com

    def start_trace(self):
        print("开始抓trace啦！！")
        trace_obj = subprocess.Popen(["./bin/diag","trace/log","-","-","%s" % self.com], shell=False)


    def stop_trace(self):
        print("正在关闭trcae")
        trace_objj = subprocess.Popen("ps -e|grep diag", shell=True, stdout=subprocess.PIPE)
        std = trace_objj.stdout.readline(100).decode()
        pid = re.findall(r"\d\d\d\d*",std)
        os.kill(int(pid[0]),signal.SIGKILL)

# gt = Gene_Trace("/dev/ttyUSB2")
# gt.stop_trace()


